<template>
  <router-view :class="[mode]" />
</template>
<script setup lang="ts">
// @ts-nocheck
import { getMobileType } from '@/utils/getMoble';
import { getUrlTemplateId } from '@/utils/minxin';
import { pathSquare } from '@/utils/minxin';
import { configData } from '@/api/templates/templates';
import { computed, watch, nextTick, onMounted, onUnmounted } from 'vue';
import { useProjectStore } from '@/store';
import { useRoute, useRouter } from 'vue-router';
import { projectRoutin } from '@/api/project/project';
import screen from '@/utils/screen';
const store = useProjectStore();
const route = useRoute();
const router = useRouter();
getUrlTemplateId();

const mode = computed(() => {
  return store.displayMode;
});

const handleFn = () => {
  if (route.name !== 'login' || route.name !== 'templateSquare') {
    getUrlTemplateId();
  }

  // if (route.query.projectId) {
  //   localStorage.setItem('projectId', String(route.query.projectId));
  // } else {
  //   // window.location.href = 'http://wz.wuzhan.art/#/portal/home';
  // }
  // });
};
store.setHeartbeatCurrent(true);

// setTimeout(() => {
//   initName();
// }, 1000);

document.addEventListener('visibilitychange', (e) => {
  if (document.visibilityState === 'hidden') {
    handleFn();
  }
});
window.addEventListener('pageshow', function (event) {
  handleFn();
  // // 增加路由判断 仅当前页面生效
  // if(window.location.pathname === "/activityMidPage"){
  //  // ...
  // }
});
window.addEventListener('beforeunload', function (event) {
  // 处理事件逻辑
  handleFn();
});
/*浏览器关闭、浏览器标签页关闭、浏览器刷新均会触发"beforeunload"事件*/
window.addEventListener('focus', (e) => handleFn());

//编辑模式查看
//http://localhost:8880/#/edit/384380806840389
//预览模式查看
//http://localhost:8880/#/web/384380806840389
//移动模式查看
//http://localhost:8880/#/wap/384380806840389
// 模板10移动端 http://localhost:8880/#/web/498056082657349/gymj
// 模板8移动端  http://localhost:8880/#/edit/505722037264453/ygzy
// 模板4移动端 http://localhost:8880/#/wap/499719735066693/wjqq
// 模板13pc  http://localhost:8880/#/edit/505722037264453/cyfh

onMounted(() => {
  window.addEventListener('message', function (event) {
    // console.log(event.data);
    if (event.data === 'moveRemove') {
      var element = document.getElementById('animationElement-lottieMove');
      element.remove();
      return;
    }
    if (event.data === 'remove') {
      sessionStorage.removeItem('PreviewType');
      // sessionStorage.clear();
    } else {
      if (event.data === 'pc' || event.data === 'wap') {
        sessionStorage.setItem('PreviewType', event.data);
        const url = window.location.href;
        const regex = /\/(\d+)/; // 匹配数字参数的正则表达式
        const match = url.match(regex); // 使用正则表达式匹配数字参数
        let numericParam;
        if (match) {
          numericParam = parseInt(match[1]); // 提取数字参数并将其转换为数字类型
          // alert(numericParam);
          getMobileType(numericParam);
        }
      }
    }
  });
});
onUnmounted(() => {
  // sessionStorage.clear();
  window.removeEventListener('message', function (event) {
    sessionStorage.removeItem('PreviewType');
  });
});

window.addEventListener('beforeunload', function (event) {});
</script>

<style lang="less" scoped>
#nprogress .bar {
  background: var(--td-brand-color) !important;
}
</style>
